package com.cjy.homework;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class HbaseTest {
    public static void main(String[] args) throws IOException {
        Configuration config = HBaseConfiguration.create();
        config.set("hbase.zookeeper.quorum","192.168.65.4");
        Connection connection = ConnectionFactory.createConnection(config);
        //"data"为表名名
        BufferedMutator mutator = connection.getBufferedMutator(TableName.valueOf("data"));
        List<Mutation>list=new ArrayList<>();
        BufferedReader br = new BufferedReader(new FileReader("E:\\Hadoop\\随机生成作业3的数据\\2023-06-05\\mysqldata2.txt"));
        String line = null ;
        while ((line=br.readLine())!=null){
            String[] split = line.split(",");
            //"vin"为行名称  "lie"为列族名称对应Hbase上创的列族
            Put put = new Put("vin".getBytes());//u001行数据
            put.addColumn("lie".getBytes(),split[0].getBytes(),split[1].getBytes());
            list.add(put);
        }
        //批次操作对象
        mutator.mutate(list); //缓存、类似于put操作
        mutator.flush(); //手动刷写到Hbase中的HDFS上

        mutator.close();

    }
}
